package dp.subsequence;

import java.util.Arrays;

public class leetCode673_findNumberOfLIS {

    public int findNumberOfLIS(int[] nums) {
        if(nums == null || nums.length == 0) return 0;
        if(nums.length == 1) return 1;
        int n = nums.length;
        int[] dp = new int[n];
        int[] count = new int[n];
        Arrays.fill(dp,1);
        Arrays.fill(count,1);
        int max = 0;
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < i; j++) {
                if(nums[i] > nums[j]){
                    if(dp[j] + 1 > dp[i]){
                        dp[i] = dp[j] + 1;
                        count[i] = count[j];
                    }else if(dp[j] + 1 == dp[i]){
                        count[i] += count[j];
                    }
                }
            }
            max = Math.max(max,dp[i]);
        }

        int res = 0;
        for (int i = 0; i < n; i++) {
            if(dp[i] == max){
                res += count[i];
            }
        }
        return res;

    }

}
